package jdbc;

import java.sql.*;
import java.util.Scanner;

public class LoginDemo {
    public static void main(String[] args) {
        Userinfo userinfo = InputUtil.getInputObject(new Userinfo(),"登录,请输入用户名和密码","登录");
        System.out.println(userinfo);
        try (Connection connection = DBUtil.getConnection();){

            Statement statement = connection.createStatement();
            String sql = "SELECT username,password FROM userinfo " +
                    "WHERE username='"+userinfo.getUsername()+
                    "' AND password='"+userinfo.getPassword()+
                    "'";
            System.out.println(sql);
            ResultSet re = statement.executeQuery(sql);
            if(re.next()){
                System.out.println("登陆成功");
                    String username = re.getString("username");
                    String password = re.getString("password");
                    System.out.println("用户名："+username+",密码："+password);
            }else{
                System.out.println("用户名或密码输入不正确");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
